const app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    reward_type: 1,
    tabList: [{
      id: 1,
      name: "技能师傅奖励记录"
    },{
      id: 2,
      name: "师傅推荐人奖励记录"
    }],
    dataList: [{
      order_sn: 'SN2303141847C4FF48'
    },{
      order_sn: 'SN2303141847C4FF22'
    },{
      order_sn: 'SN2303141847C4FF33'
    }],
    finished: false,
    page: 1,
    recordList: [],
    detailData: {}
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    this.getCentreData();
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {
    this.getOrderData();
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  },
  getCentreData() {
    let baseUrl = app.getNetAddresss("plugin.be-within-call.frontend.manage.reward-centre");
    app._postNetWork({
      url: baseUrl,
      success: ({data : { data,result,msg }}) => {
        if (result !== 1) {
          wx.showToast({
            title: msg,
          });
          return false;
        }
        this.setData({
          detailData: data
        })
        this.getOrderData();
      }
    });
  },
  getOrderData () {
    if (this.data.finished) return;
    let baseUrl = app.getNetAddresss("plugin.be-within-call.frontend.manage.get-dividend");
    app._postNetWork({
      url: baseUrl,
      data: {
        page: this.data.page,
        reward_type: this.data.reward_type
      },
      success: (respone) => {
        if (respone.data.result !== 1) {
          wx.showToast({
            title: respone.data.msg,
          });
          return false;
        }
        let res = respone.data.data;
        let finished = false;
        let recordList = [];
        if (res.data.length === 0 || res.data.length < res.per_page || res.current_page === res.last_page) {
          finished = true;
        }
        recordList = this.data.recordList.concat(res.data);
        this.setData({
          finished,
          recordList,
          page: ++this.data.page
        });

      }
    });
  },
  onClickTab(e) {
    this.setData({
      reward_type: e.detail.name,
      page: 1,
      recordList: [],
      finished: false
    })
    this.getOrderData();
  }
})